<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="6" :xs="24">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>个人信息</span>
          </div>
          <div>
            <div class="text-center">
              <userAvatar :user="user" />
            </div>
            <ul class="list-group list-group-striped">
              <li class="list-group-item">
                <svg-icon icon-class="user" />用户名
                <div class="pull-right">{{ user.userName }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="phone" />手机号码
                <div class="pull-right">{{ user.phonenumber }}</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="email" />用户邮箱
                <div class="pull-right" v-if="user.email">{{user.email}}</div>
                <div class="pull-right" v-else>无</div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="tree" />所属社团
                <a href="javascript:void(0)" class="pull-right"
                   v-if="user.dept && user.deptId && user.deptStatus=='0'"
                   @click="detailClick(user.dept)">{{ user.dept.deptName }}</a>
                <a href="javascript:void(0)" class="pull-right"
                   v-if="user.dept && user.deptId && user.deptStatus=='1'"
                   @click="detailClick(user.dept)">{{ user.dept.deptName }}（待审核）</a>
                <div class="pull-right" v-if="!user.deptId">
                  <span style="padding-right: 10px">无</span>
                  <el-button style="padding: 5px 10px;" type="success" plain size="mini" round @click="sqClick">申请</el-button>
                </div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="post" />所属组织
                <div class="pull-right" v-if="postGroup">{{ postGroup }}</div>
                <div class="pull-right" v-else>
                  <span style="padding-right: 10px">无</span>
                  <el-button style="padding: 5px 10px;" type="success" plain size="mini" round>申请</el-button>
                </div>
              </li>
              <li class="list-group-item">
                <svg-icon icon-class="date" />注册时间
                <div class="pull-right">{{ parseTime(user.createTime, '{y}-{m}-{d}') }}</div>
              </li>
            </ul>
          </div>
        </el-card>
      </el-col>
      <el-col :span="18" :xs="24">
        <el-card>
          <div slot="header" class="clearfix">
            <span>基本资料</span>
          </div>
          <el-tabs v-model="activeTab">
            <el-tab-pane label="基本资料" name="userinfo">
              <userInfo :user="user" />
            </el-tab-pane>
            <el-tab-pane label="修改密码" name="resetPwd">
              <resetPwd :user="user" />
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import userAvatar from "./userAvatar";
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import { getUserProfile } from "@/api/user";
import Sponsor from '@/views/register/Sponsor'

export default {
  name: "Profile",
  components: { Sponsor, userAvatar, userInfo, resetPwd },
  data() {
    return {
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo"
    };
  },
  created() {
    this.getUser();
  },
  methods: {
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
      });
    },
    sqClick(){
      sessionStorage.removeItem('deptListName')
      this.$router.push('/dept/index')
    },
    detailClick(val) {
      sessionStorage.setItem("deptName",val.deptName)
      this.$router.push({
        path: '/dept/index/list/edit',
        query: {
          id: val.deptId
        }
      })
    },
  }
};
</script>

<style scoped>
.app-container{
  padding: 30px 100px;
  text-align: left;
}
/deep/.el-form-item__label{
  font-weight: 600;
}
/deep/.el-card__header{
  font-size: 16px;
  padding: 14px 15px 7px;
  min-height: 40px;
  color: #303133;
}
/deep/.el-card__body{
  padding: 15px 20px 20px 20px;
}
/deep/.el-button--mini, .el-button--small {
   font-size: 13px;
 }
.list-group-striped > .list-group-item {
  border-left: 0;
  border-right: 0;
  border-radius: 0;
  padding-left: 0;
  padding-right: 0;
}

.list-group {
  padding: 20px 0;
  padding-left: 0px;
  list-style: none;
}

.list-group-item {
  border-bottom: 1px solid #e7eaec;
  border-top: 1px solid #e7eaec;
  margin-bottom: -1px;
  padding: 11px 0px;
  font-size: 13px;
}
.pull-right {
  float: right !important;
}
.text-center {
  text-align: center
}
</style>
